<?php
namespace Home\Controller;
use Think\Controller;

class ReplyController extends CommonController {
    public function index(){
       
        $data  = M("reply");
        $count = $data->where('1=1')->count();
        
        $page  = new \Think\Page($count,C("PAGESIZE"));
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
    	
    	$list  = $data->where("1=1")->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
        $show  = $page->show();
    	
    	$this->assign( "list", $list);
    	$this->assign( "page", $show);
        $this->display();
    
    }
   
    public function deletes(){
    
    	$ajax = I('post.id');
    	$data = M('reply');
    	$data->delete($ajax);
  
    }
   
    public function inserts(){
    	
    	if($_POST){
    		
    		if(!empty(I('post.reply'))&& !empty(I('post.response'))){
    			$data['reply']    = I('post.reply');
		    	$data['response'] = I('post.response');
		    	$inst = M('reply');
		    	$inst->add($data);
		    	$this->success('添加成功', '',0);
    		} else {
    			$this->error('数据不能为空,添加失败！', '',0);
    		}			
    	}
    
    }
    
    public function updates(){

    	if($_POST){
    		
    		if(!empty(I('post.reply')) && !empty(I('post.response'))){
	    		
                $data['id']       = I('post.id');
	    		$data['reply']    = I('post.reply');
	    		$data['response'] = I('post.response');
	    		$upt = M('reply');
	    		$upt->where("id={$data['id']}")->save($data);
    		
            } else {
                $this->error('数据不能为空,编辑失败！', '',0);
            }
    	
    	}
    
    }
}